package com.example.androidmqtt.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.androidmqtt.Entry.News;
import com.example.androidmqtt.Vo.NewsDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author: hss
 * @time: 2022/9/14
 */
@Mapper
public interface NewsMapper extends BaseMapper<News> {



    //多表详情信息
    @Select("select news_id newsId,news_title newsTitle,news_content newsContent," +
            "user.user_name newsAuthor,user.user_avatar authorAvatar,department.department_name newsDepartment," +
            "news_appendix newsAppendix,DATE_FORMAT(publish_time,'%Y-%m-%d %H:%i') newsPublishTime " +
            "from news " +
            "left join user on news.news_author=user.user_id " +
            "left join department on news.news_department=department.department_id " +
            "where news.news_department in " +
            "(select sub_department from subscribe where sub_user=#{userId} and iscancel=0) " +
            "and news.iscancel=0 " +
            "order by publish_time desc, news_department")
    List<NewsDetail> selectListByUser(Integer userId);

    //全部消息
    @Select("select news_id newsId,news_title newsTitle,news_content newsContent," +
            "user.user_name newsAuthor,user.user_avatar authorAvatar,department.department_name newsDepartment," +
            "news_appendix newsAppendix,DATE_FORMAT(publish_time,'%Y-%m-%d %H:%i') newsPublishTime " +
            "from news " +
            "left join user on news.news_author=user.user_id " +
            "left join department on news.news_department=department.department_id " +
            "where news.iscancel=0 " +
            "order by publish_time desc, news_department")
    List<NewsDetail> selectAll();
}
